package com.zjt.smart.util;

import android.util.TypedValue;

import com.zjt.smart.app.MainApplication;

public class DimensionUtil {

    public static int dipToPx(float value) {
        float px = TypedValue.applyDimension(1, value, MainApplication.getApp().getResources().getDisplayMetrics());
        return Math.round(px);
    }

    public static int spToPx(float value) {
        float px = TypedValue.applyDimension(2, value, MainApplication.getApp().getResources().getDisplayMetrics());
        return Math.round(px);
    }

    public static int mmtoPx(float value) {
        float px = TypedValue.applyDimension(5, value, MainApplication.getApp().getResources().getDisplayMetrics());
        return Math.round(px);
    }

    public static int ptToPx(float value) {
        float px = TypedValue.applyDimension(3, value, MainApplication.getApp().getResources().getDisplayMetrics());
        return Math.round(px);
    }

    public static int pxToDip(float pxValue) {
        float scale = MainApplication.getApp().getResources().getDisplayMetrics().density;
        return (int)(pxValue / scale + 0.5F);
    }
}